# -*- coding: utf-8 -*-

import time
import sys
import math
import random
import datetime

class cc:
    fw = [2612, 638, 2740, 783]
    bs = 0x0F43  #匕首 斧头
    clist=[0x1BD7,0x3190,0x318F,0x3199,0x2F5F,0x3191,0x1870]
    inj = 'can\'t|enough|not'         #无法砍柴的系统信息
    xz = 0x417A6F09  #存放的箱子
    homex = 913     #箱子跟前的坐标   x y
    homey = 1175
    homexy = 0x40CFD5A9  #箱子跟前的符石
    homexz_x=825
    homexz_y=1208
    dian = 0x40CFD5B9   #砍柴点临时符石
    count=0     #计数器

    def __init__(self):
        self.fw = [2612, 638, 2740, 783]
        self.bs = 0x409A32F1
        self.inj = 'can\'t|enough|not'
        self.xz = 0x417A6F09
        self.homex = 913
        self.homey = 1175
        self.homexz_x=825
        self.homexz_y=1208
        self.homexy = 0x40CFD5A9
        self.dian = 0x40CFD5B9


    def kc(self,Tile, x, y, z):
        st = datetime.datetime.now()
        k = 1
        c = 0
        while k:
            #if FindType(self.bs,Backpack())<1:
            #    self.gohome()
            if ObjAtLayer(LhandLayer()) < 1:
                equipt(LhandLayer(), self.bs)
                time.sleep(0.2)
            UseObject(ObjAtLayer(LhandLayer()))
            time.sleep(0.1)
            TargetToTile(Tile, x, y, z)
            if InJournalBetweenTimes(self.inj, st, datetime.datetime.now())>0:
                k = 0
               #print(u"没有")
            c += 1
            #print(c)
            if c == 30:
                k = 0
            #if FindType(self.bs,Backpack())<1:
            #    self.gohome()
            while FindType(0x1BDD,Backpack()):
                if ObjAtLayer(LhandLayer()) < 1:
                    equipt(LhandLayer(), self.bs)
                    time.sleep(0.2)
                UseObject(ObjAtLayer(LhandLayer()))
                time.sleep(0.1)
                TargetToObject(FindItem())
            if MaxWeight() - Weight() < 100:
                self.gohome()


    def c(self):
        NewMoveXY(self.homexz_x, self.homexz_y, True, 0, True)
        UOSay(u'开箱子')
        UOSay(u'bank')
        UseObject(self.xz)
        UseObject(self.xz)
        time.sleep(2)
        for cl in self.clist:
            while FindType(cl, Backpack()):
                self.count=self.count+GetQuantity(FindItem())
                MoveItem(FindItem(), 0, self.xz, 0, 0, 0)
                time.sleep(0.8)
        print(self.count)
        while GetHP(Self())!= GetMaxHP(Self()):
            print(u'恢复中...')
            time.sleep(1)
            


    def gj(self):
        MoveItem(FindType(0x1BF2,self.xz),300,Backpack(),0,0,0)
        time.sleep(0.8)
        while CountEx(0x1EB8,0x0000,self.xz)<=3:    
            if FindType(0x1EB8,Backpack()):
                UseObject(FindItem())  
                time.sleep(0.1) 
                WaitGump(8)
                time.sleep(0.1) 
                WaitGump(23)
                time.sleep(0.1)  
                WaitGump(0)
                time.sleep(2)
                MoveItem(FindType(0x1EB8,Backpack()),1,self.xz,0,0,0)
                time.sleep(0.8)
            else:
                MoveItem(FindType(0x1EB8,self.xz),1,Backpack(),0,0,0)
                time.sleep(0.8)
        
                                   
        while CountEx(0x0F43,0x0000,self.xz)<=4:    
            if FindType(0x1EB8,Backpack()):
                UseObject(FindItem())  
                time.sleep(0.1) 
                WaitGump(8)
                time.sleep(0.1) 
                WaitGump(30)
                time.sleep(0.1)  
                WaitGump(0)
                MoveItem(FindType(0x0F43,Backpack()),1,self.xz,0,0,0)
            else:
                MoveItem(FindType(0x1EB8,self.xz),1,Backpack(),0,0,0)
                time.sleep(0.8)

        while Count(0x0F43)<3:
            MoveItem(FindType(0x0F43,self.xz),1,Backpack(),0,0,0)
            time.sleep(0.8)                    
     

        MoveItem(FindType(0x1BF2,Backpack()),0,self.xz,0,0,0)
        time.sleep(0.8)     

    def gohome(self):
        print(u'存木头做工具')
        x = GetX(Self())
        y = GetY(Self())
        if FindType(0x1F14, Backpack()):
            while 'dian' in GetTooltip(self.dian):
                Cast('Mark')
                time.sleep(3)
                TargetToObject(self.dian)
                time.sleep(1)
            UseObject(self.dian)
            time.sleep(1)
            ConsoleEntryUnicodeReply('dian')
            time.sleep(1)

            while GetX(Self()) != self.homex or GetY(Self()) != self.homey:
                UOSay(u'位置：' + str(x) + ':' + str(y))
                Cast('Recall')
                time.sleep(3)
                TargetToObject(self.homexy)
                time.sleep(2)
            self.c()
            #self.gj()
            while GetX(Self()) == self.homexz_x and GetY(Self()) == self.homexz_y:
                UOSay(u'位置：' + str(x) + ':' + str(y))
                Cast('Recall')
                time.sleep(3)
                TargetToObject(self.dian)
                time.sleep(2)
        else:
            NewMoveXY(self.homex, self.homey, False, 0, True)
            self.c()
            #self.gj()
            NewMoveXY(x, y, False, 1, True)



